/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import src.ClaseCargo;
import controles.ControlCreacion;
import controles.ControlModificacion;
import javax.swing.JOptionPane;
import src.Core;
import src.LinkedLists;

/**
 *
 * @author Strauzen
 */
public class VentanaAnadir extends javax.swing.JFrame {

    int padre;
    Ventana1 v1;
    Ventana3 v3;
    VentanaPersonaje vp;
    VentanaCargo vca;
    VentanaAcontecimiento vac;
    VentanaColectivo vco;
    VentanaModificarRelaciones vmr;
    ClaseCargo CC;
    
    /**
     * Creates new form VentanaAnadir
     */
    public VentanaAnadir(int padre, Ventana1 v1,Ventana3 v3) {
        this.padre = padre;
        this.v1 = v1;
        this.v3 = v3;
        initComponents();
    }

    public VentanaAnadir(int i, Ventana1 v1, Ventana3 v3, VentanaPersonaje vp, ClaseCargo CC) {
        this.padre = i;
        this.v1 = v1;
        this.v3 = v3;
        this.vp = vp;
        this.CC = CC;
        initComponents();
    }
    
    public VentanaAnadir(int i, Ventana1 v1,Ventana3 v3, VentanaCargo vca) {
        this.padre = i;
        this.v1 = v1;
        this.v3 = v3;
        this.vca = vca;
        initComponents();
    }
    
    public VentanaAnadir(int i, Ventana1 v1, Ventana3 v3, VentanaColectivo vco) {
        this.padre = i;
        this.v1 = v1;
        this.v3 = v3;
        this.vco = vco;
        initComponents();
    }
    
    public VentanaAnadir(int i, Ventana1 v1, Ventana3 v3, VentanaAcontecimiento vac) {
        this.padre = i;
        this.v1 = v1;
        this.v3 = v3;
        this.vac = vac;
        initComponents();
    }

    public VentanaAnadir(int padre, VentanaModificarRelaciones vmr, int idPadre) {
        this.padre = padre;
        this.idPadre = idPadre;
        this.vmr = vmr;
        initComponents();
    }
    
    public VentanaAnadir(int padre, VentanaModificarRelaciones vmr,ClaseCargo CC, int idPadre) {
        this.padre = padre;
        this.idPadre = idPadre;
        this.vmr = vmr;
        this.CC = CC;
        initComponents();
    }
        
    public void setTexto(String txt)
    {
        jTextArea_vanSeleccion.setText(txt);
    }
    
    public String getTexto()
    {
        return jTextArea_vanSeleccion.getText();
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jButton_vanAnadir = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea_vanSeleccion = new javax.swing.JTextArea();
        jLabel_vanSeleccion = new javax.swing.JLabel();
        jTextField_vanSeleccion = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Elija los que quiera añadir");

        jButton_vanAnadir.setText("Añadir");
        jButton_vanAnadir.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_vanAnadirMouseClicked(evt);
            }
        });

        jTextArea_vanSeleccion.setColumns(20);
        jTextArea_vanSeleccion.setEditable(false);
        jTextArea_vanSeleccion.setRows(5);
        jScrollPane2.setViewportView(jTextArea_vanSeleccion);

        jLabel_vanSeleccion.setText("Indice que desea añadir:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel_vanSeleccion)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField_vanSeleccion, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 168, Short.MAX_VALUE)
                        .addComponent(jButton_vanAnadir))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_vanAnadir)
                    .addComponent(jLabel_vanSeleccion)
                    .addComponent(jTextField_vanSeleccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_vanAnadirMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_vanAnadirMouseClicked
        // TODO add your handling code here:
        try{
            Integer.parseInt(this.jTextField_vanSeleccion.getText());

            switch(padre){
                case 4:
                    this.setVisible(false);
                    vp.setVisible(true);
                    CC.setIdCargo(Integer.parseInt(jTextField_vanSeleccion.getText()));
                    LinkedLists.anadeCargoParaPersonajes(CC);
                    this.dispose();
                    break;
                case 5:
                    this.setVisible(false);
                    vca.setVisible(true);
                    LinkedLists.anadeFicheroParaCargos(Integer.parseInt(jTextField_vanSeleccion.getText()));
                    this.dispose();
                    break;
                case 6:
                    this.setVisible(false);
                    vco.setVisible(true);
                    LinkedLists.anadeFicheroParaColectivos(Integer.parseInt(jTextField_vanSeleccion.getText()));
                    this.dispose();
                    break;
                case 7:
                    this.setVisible(false);
                    vac.setVisible(true);
                    LinkedLists.anadeFicheroParaAcontecimientos(Integer.parseInt(jTextField_vanSeleccion.getText()));
                    this.dispose();
                    break;
                case 8:
                    //relacion documentoPersonaje
                    vmr.setVisible(true);
                    this.setVisible(false);
                    Core.setDocumento(padre);
                    Core.linkaPersonajeConDocumento(idPadre,Integer.parseInt(jTextField_vanSeleccion.getText()));
                    this.dispose();
                    break;
                case 9:
                    //relacion documentoAcontecimiento
                    vmr.setVisible(true);
                    this.setVisible(false);
                    Core.setDocumento(padre);
                    Core.linkaAcontecimientoConDocumento(idPadre,Integer.parseInt(jTextField_vanSeleccion.getText()));
                    this.dispose();
                    break;
                case 10:
                    //relacion documentoColectivo
                    vmr.setVisible(true);
                    this.setVisible(false);
                    Core.setDocumento(padre);
                    Core.linkaColectivoConDocumento(idPadre,Integer.parseInt(jTextField_vanSeleccion.getText()));
                    this.dispose();
                    break;
                case 11:
                    //relacion acontecimientoFichero
                    vmr.setVisible(true);
                    this.setVisible(false);
                    Core.linkaAcontecimientoFichero(idPadre,Integer.parseInt(jTextField_vanSeleccion.getText()));
                    this.dispose();
                    break;
                case 12:
                    //relacion colectivoFichero
                    vmr.setVisible(true);
                    this.setVisible(false);
                    Core.linkaColectivoFichero(idPadre,Integer.parseInt(jTextField_vanSeleccion.getText()));
                    this.dispose();
                    break;
                case 13:
                    //Relacion personajeAlias
                    vmr.setVisible(true);
                    this.setVisible(false);
                    Core.linkaPersonajeAlias(idPadre,jTextField_vanSeleccion.getText());
                    this.dispose();
                    break;
                case 14:
                    //Relacion personajeCargo
                    vmr.setVisible(true);
                    this.setVisible(false);
                    CC.setIdCargo(idPadre);
                    Core.linkaPersonajeCargo(idPadre,CC);
                    this.dispose();
                    break;
                default:
                    this.setVisible(false);
                    if(ControlCreacion.creando == ControlCreacion.Creacion.acontecimiento)
                    {
                        Core.linkaAcontecimientoConDocumento(Core.getDocumento(),Integer.parseInt(jTextField_vanSeleccion.getText()));
                    } else if(ControlCreacion.creando == ControlCreacion.Creacion.colectivo)
                    {
                        Core.linkaColectivoConDocumento(Core.getDocumento(),Integer.parseInt(jTextField_vanSeleccion.getText()));
                    } else if(ControlCreacion.creando == ControlCreacion.Creacion.personaje)
                    {
                        Core.linkaPersonajeConDocumento(Core.getDocumento(),Integer.parseInt(jTextField_vanSeleccion.getText()));
                    }
                    v3.setVisible(true);
                    this.dispose();
                    break;
            }
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Por favor introduzca el numero que represente el indice que desea añadir");
        }
    }//GEN-LAST:event_jButton_vanAnadirMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_vanAnadir;
    private javax.swing.JLabel jLabel_vanSeleccion;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea_vanSeleccion;
    private javax.swing.JTextField jTextField_vanSeleccion;
    // End of variables declaration//GEN-END:variables
    private int idPadre;
}
